//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package wudashan.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.UnsupportedEncodingException;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import wudashan.EDRXSimulator;

public class DataButton extends JButton {
    public DataButton(final EDRXSimulator edrxSimulator) {
        super("发送数据");
        this.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int i = edrxSimulator.getTabbedPane().getSelectedIndex();
                String payload;
                switch(i) {
                    case 0:
                        payload = edrxSimulator.getHexMsgArea().getText();
                        break;
                    case 1:
                        payload = edrxSimulator.getJsonMsgArea().getText();
                        break;
                    default:
                        payload = null;
                }

                if (!edrxSimulator.isHasRegister()) {
                    JOptionPane.showMessageDialog(edrxSimulator, "请先注册设备！");
                } else if (payload != null && payload.length() != 0) {
                    edrxSimulator.getResource().setIsRegister(false);
                    edrxSimulator.getResource().changed();
                } else {
                    JOptionPane.showMessageDialog(edrxSimulator, "上报的数据不能为空！");
                }
            }
        });
    }

    private byte[] convertMsgToByte(String payload) {
        try {
            return payload.getBytes("UTF-8");
        } catch (UnsupportedEncodingException var3) {
            var3.printStackTrace();
            return null;
        }
    }
}
